#!/bin/sh

CLANG="clang"
LLVM_BIN="/home/guest/cpu/llvm-thumips/llvm-3.1.src/Release+Asserts/bin"
#LLVM_BIN="/usr/bin/llc"
LLC=$LLVM_BIN"/llc -march=mipsel -mcpu=mips32 -mattr=-condmov,-bitcount,+o32,-swap"
GCC_PREFIX="mips-sde-elf-"
AS=$GCC_PREFIX"as -EL -g -mips1 -msoft-float"


if [ $# != 3 ]; then
  echo "usage: thumips-cc [flag] [in] [out]"
  exit
fi

BCFILE=`tempfile -s .bc`
echo $BCFILE
$CLANG -O0 -emit-llvm -c -g  $1 -o $BCFILE $2  &&
#ASMFILE=`tempfile -s .s`
#$LLC  -o $ASMFILE $BCFILE &&
#$AS -KPIC -o $3 $ASMFILE &&
$LLC -o - $BCFILE | $AS -KPIC -o $3 
rm $BCFILE  
#rm $ASMFILE 
